<script setup>
import { ref, onMounted, reactive } from "vue";

const showBoat = ref(false);
const showFacts = ref(false);
const currentFact = ref(0);

const facts = reactive([
  {
    title: "端午节起源",
    content:
      "端午节起源于中国古代，距今已有2000多年历史，是纪念爱国诗人屈原的传统节日。",
  },
  {
    title: "赛龙舟",
    content:
      "赛龙舟是端午节最具代表性的活动之一，象征着人们对屈原的追思和对生活的热爱。",
  },
  {
    title: "粽子文化",
    content:
      "粽子是端午节的传统食品，用糯米裹各种馅料，再用粽叶包裹成三角形或其他形状。",
  },
  {
    title: "艾草菖蒲",
    content: "端午节挂艾草和菖蒲可以驱邪避灾，保佑家人平安健康。",
  },
]);

function showNextFact() {
  currentFact.value = (currentFact.value + 1) % facts.length;
}

function showPrevFact() {
  currentFact.value = (currentFact.value - 1 + facts.length) % facts.length;
}

onMounted(() => {
  setTimeout(() => {
    showBoat.value = true;
  }, 1000);

  setTimeout(() => {
    showFacts.value = true;
  }, 1500);
});
</script>

<template>
  <div class="festival-container">
    <div class="header">
      <h1 class="title">欢度端午节</h1>
      <p class="subtitle">Dragon Boat Festival</p>
    </div>

    <div class="content">
      <div class="info-section">
        <div class="info-card">
          <h2>端午节的由来</h2>
          <p>
            端午节是中国传统节日，为每年农历五月初五。据传起源于古人对屈原的纪念，他是中国古代伟大的爱国诗人。
          </p>
        </div>

        <div class="info-card">
          <h2>传统习俗</h2>
          <ul>
            <li><span class="custom-icon">🚣‍♂️</span> 赛龙舟</li>
            <li><span class="custom-icon">🍙</span> 吃粽子</li>
            <li><span class="custom-icon">🌿</span> 挂艾草菖蒲</li>
            <li><span class="custom-icon">👝</span> 佩香囊</li>
          </ul>
        </div>

        <div class="fact-slider" v-if="showFacts">
          <div class="fact-navigation">
            <button @click="showPrevFact" class="nav-btn prev-btn">&lt;</button>
            <button @click="showNextFact" class="nav-btn next-btn">&gt;</button>
          </div>
          <transition name="slide" mode="out-in">
            <div class="fact-card" :key="currentFact">
              <h3>{{ facts[currentFact].title }}</h3>
              <p>{{ facts[currentFact].content }}</p>
            </div>
          </transition>
          <div class="fact-dots">
            <span
              v-for="(fact, index) in facts"
              :key="index"
              :class="['fact-dot', { active: index === currentFact }]"
              @click="currentFact = index"
            ></span>
          </div>
        </div>
      </div>

      <div class="animation-container">
        <div class="water"></div>
        <div :class="['dragon-boat', { 'show-boat': showBoat }]">
          <div class="boat-paddlers">
            <div class="paddler"></div>
            <div class="paddler"></div>
            <div class="paddler"></div>
          </div>
        </div>
        <div class="zongzi-container">
          <div class="zongzi zongzi-1"></div>
          <div class="zongzi zongzi-2"></div>
          <div class="zongzi zongzi-3"></div>
        </div>
        <div class="clouds">
          <div class="cloud cloud-1"></div>
          <div class="cloud cloud-2"></div>
        </div>
      </div>

      <div class="interactive-section">
        <button @click="$emit('change-tab', 'race')" class="festival-btn">
          赛龙舟
        </button>
        <button @click="$emit('change-tab', 'zongzi')" class="festival-btn">
          包粽子
        </button>
        <a
          href="https://baike.baidu.com/item/端午节"
          target="_blank"
          class="festival-btn"
          >了解更多</a
        >
      </div>
    </div>

    <div class="footer">
      <p>祝大家端午节安康！</p>
    </div>
  </div>
</template>

<style scoped>
.festival-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  font-family: "Microsoft YaHei", sans-serif;
  color: #333;
}

.header {
  text-align: center;
  margin-bottom: 40px;
  background: linear-gradient(135deg, #ff9a3c, #ff5252);
  padding: 30px;
  border-radius: 10px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  animation: fadeInDown 1s ease-out;
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.title {
  font-size: 3.5rem;
  margin: 0;
  color: #fff;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.subtitle {
  font-size: 1.5rem;
  color: #fff;
  opacity: 0.9;
  margin-top: 10px;
}

.content {
  display: grid;
  grid-template-columns: 1fr;
  gap: 30px;
}

@media (min-width: 768px) {
  .content {
    grid-template-columns: 1fr 1fr;
  }
}

.info-section {
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: fadeIn 1s ease-out 0.3s both;
}

.info-card {
  background-color: #fff;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
  border-left: 5px solid #ff5252;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.info-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 15px rgba(0, 0, 0, 0.1);
}

.info-card h2 {
  color: #ff5252;
  margin-top: 0;
}

.info-card ul {
  padding-left: 20px;
  list-style-type: none;
}

.info-card li {
  margin-bottom: 12px;
  display: flex;
  align-items: center;
}

.custom-icon {
  margin-right: 10px;
  font-size: 1.2rem;
}

.fact-slider {
  background-color: #fff;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
  position: relative;
  border-left: 5px solid #8bc34a;
  overflow: hidden;
  min-height: 150px;
}

.fact-navigation {
  position: absolute;
  top: 50%;
  width: 100%;
  left: 0;
  transform: translateY(-50%);
  display: flex;
  justify-content: space-between;
  padding: 0 10px;
  z-index: 2;
}

.nav-btn {
  background-color: rgba(255, 255, 255, 0.7);
  border: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  cursor: pointer;
  transition: background-color 0.3s;
}

.nav-btn:hover {
  background-color: rgba(255, 82, 82, 0.2);
}

.fact-card {
  text-align: center;
  padding: 0 30px;
}

.fact-card h3 {
  color: #8bc34a;
  margin-bottom: 10px;
}

.fact-dots {
  display: flex;
  justify-content: center;
  margin-top: 15px;
  gap: 8px;
}

.fact-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: #e0e0e0;
  cursor: pointer;
  transition: background-color 0.3s;
}

.fact-dot.active {
  background-color: #8bc34a;
}

.animation-container {
  position: relative;
  height: 300px;
  background-color: #e6f7ff;
  border-radius: 10px;
  overflow: hidden;
  animation: fadeIn 1s ease-out 0.6s both;
}

.water {
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 60%;
  background: linear-gradient(180deg, #4fc3f7, #0288d1);
  border-radius: 0 0 10px 10px;
}

.water::before {
  content: "";
  position: absolute;
  top: -10px;
  left: 0;
  width: 100%;
  height: 20px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 320'%3E%3Cpath fill='%234fc3f7' fill-opacity='1' d='M0,160L48,181.3C96,203,192,245,288,229.3C384,213,480,139,576,128C672,117,768,171,864,197.3C960,224,1056,224,1152,197.3C1248,171,1344,117,1392,90.7L1440,64L1440,320L1392,320C1344,320,1248,320,1152,320C1056,320,960,320,864,320C768,320,672,320,576,320C480,320,384,320,288,320C192,320,96,320,48,320L0,320Z'%3E%3C/path%3E%3C/svg%3E");
  background-size: cover;
  animation: wave 10s linear infinite;
}

@keyframes wave {
  0% {
    background-position-x: 0;
  }
  100% {
    background-position-x: 1000px;
  }
}

.dragon-boat {
  position: absolute;
  width: 180px;
  height: 60px;
  background-color: #ff5252;
  border-radius: 50px;
  bottom: 40px;
  left: -200px;
  transform: perspective(500px) rotateY(15deg);
  transition: left 2s ease-in-out;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.dragon-boat::before {
  content: "";
  position: absolute;
  width: 30px;
  height: 30px;
  background-color: #ffd700;
  border-radius: 50%;
  top: -15px;
  left: 10px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.dragon-boat::after {
  content: "";
  position: absolute;
  width: 30px;
  height: 30px;
  background-color: #ffd700;
  border-radius: 50%;
  top: -15px;
  right: 10px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.boat-paddlers {
  display: flex;
  justify-content: space-around;
  width: 100%;
  height: 100%;
  padding: 5px 20px;
}

.paddler {
  width: 10px;
  height: 20px;
  background-color: #333;
  border-radius: 50%;
  position: relative;
  top: -15px;
}

.paddler::after {
  content: "";
  position: absolute;
  width: 5px;
  height: 15px;
  background-color: #333;
  bottom: -10px;
  left: 2.5px;
  animation: paddle 1s infinite alternate;
}

@keyframes paddle {
  0% {
    transform: rotate(-20deg);
  }
  100% {
    transform: rotate(20deg);
  }
}

.show-boat {
  left: calc(50% - 90px);
  animation: rowing 3s ease-in-out infinite;
}

@keyframes rowing {
  0%,
  100% {
    transform: perspective(500px) rotateY(15deg) translateY(0);
  }
  50% {
    transform: perspective(500px) rotateY(15deg) translateY(-10px);
  }
}

.zongzi-container {
  position: absolute;
  width: 100%;
  bottom: 20px;
}

.zongzi {
  position: absolute;
  width: 30px;
  height: 40px;
  background-color: #8bc34a;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  animation: float 3s ease-in-out infinite;
  cursor: pointer;
  transition: transform 0.3s ease;
}

.zongzi:hover {
  transform: scale(1.2) rotate(10deg);
}

.zongzi-1 {
  left: 20%;
  animation-delay: 0.5s;
}

.zongzi-2 {
  left: 50%;
  animation-delay: 1s;
}

.zongzi-3 {
  left: 80%;
  animation-delay: 1.5s;
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-15px);
  }
}

.clouds {
  position: absolute;
  width: 100%;
  height: 40%;
  top: 0;
}

.cloud {
  position: absolute;
  background-color: rgba(255, 255, 255, 0.8);
  border-radius: 50px;
}

.cloud-1 {
  width: 100px;
  height: 30px;
  top: 20px;
  left: -100px;
  animation: moveCloud 30s linear infinite;
}

.cloud-2 {
  width: 70px;
  height: 20px;
  top: 50px;
  left: -70px;
  animation: moveCloud 25s linear infinite 5s;
}

.cloud::before,
.cloud::after {
  content: "";
  position: absolute;
  background-color: rgba(255, 255, 255, 0.8);
  border-radius: 50%;
}

.cloud-1::before {
  width: 50px;
  height: 50px;
  top: -20px;
  left: 20px;
}

.cloud-1::after {
  width: 40px;
  height: 40px;
  top: -15px;
  left: 60px;
}

.cloud-2::before {
  width: 35px;
  height: 35px;
  top: -15px;
  left: 15px;
}

.cloud-2::after {
  width: 30px;
  height: 30px;
  top: -10px;
  left: 40px;
}

@keyframes moveCloud {
  from {
    left: -100px;
  }
  to {
    left: 100%;
  }
}

.interactive-section {
  grid-column: 1 / -1;
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-top: 20px;
  flex-wrap: wrap;
  animation: fadeIn 1s ease-out 0.9s both;
}

.festival-btn {
  background-color: #ff5252;
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 30px;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 10px rgba(255, 82, 82, 0.3);
  text-decoration: none;
  display: inline-block;
}

.festival-btn:hover {
  background-color: #ff3636;
  transform: translateY(-3px);
  box-shadow: 0 6px 15px rgba(255, 82, 82, 0.4);
}

.festival-btn:active {
  transform: translateY(-1px);
}

.footer {
  margin-top: 50px;
  text-align: center;
  font-size: 1.2rem;
  color: #ff5252;
  font-weight: bold;
  animation: fadeIn 1s ease-out 1.2s both;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.slide-enter-active,
.slide-leave-active {
  transition: transform 0.5s ease, opacity 0.5s ease;
}

.slide-enter-from {
  transform: translateX(50px);
  opacity: 0;
}

.slide-leave-to {
  transform: translateX(-50px);
  opacity: 0;
}
</style>